package com.yetm.controller;

import com.yetm.po.User;
import com.yetm.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Controller
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    //@Autowired
    private UserService userService;

    @Autowired
    @Qualifier("userServiceImpl") //存在多个userService类型时需要加上@Qualifier
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "login", method = RequestMethod.POST)
    @ApiOperation(value = "用户登录", notes = "返回token")
    @ResponseBody
    public String login(@RequestBody User user, @RequestParam("token") String token) {
        // /jsp/success.jsp
        System.out.println(user);
        return "success:" + token;
    }

    @PostMapping("/register")
    @ResponseBody
    @ApiOperation(value = "用户注册")
    public String register(@Valid User user) {
        userService.register();
        return "success";
    }

    @GetMapping("/getUser/{id}")
    @ApiOperation("用户信息接口")
    @ResponseBody
    public User getUser(@PathVariable("id") String id){
        User user = userService.getUser(id);
        return user;
    }
}
